import random
class StudentSys(object):
    def __init__(self):
        self.students = []
# 全局变量

    def print_menu(self):
        print("=" * 50)
        print("\t~学生管理系统1.0版本~")
        print("\t1:添加学生信息")
        print("\t2:删除学生信息")
        print("\t3:修改学生信息")
        print("\t4:查找学生信息")
        print("\t5:显示学生信息")
        print("\t6:退出学生信息系统")
        print("=" * 50)
        print("\n")
        if 

    def add_info(self):

        student = {}  # 空的字典
        Identify = input("请输入要添加的学生编号")
        name = input("请输入要添加的学生姓名")
        phone = input("请输入要添加的学生电话")
        WeChat = input("请输入要添加的学生微信")
        student["Identify"] = Identify
        student["name"] = name
        student["phone"] = phone
        student["WeChat"] = WeChat
        # students.insert(0,student)#添加列表的开头
        self.students.append(student)  # 添加列表的末尾

    def display(self):
        print("\n")
        print("\t\t当前学生信息")
        print("~" * 70)
        print("\t学号\t姓名\t电话\t微信\t")
        for student in self.students:
            print("~" * 70)
            print("\t" + student["Identify"] + "\t\t" + student["name"] + "\t\t" + student["phone"] + "\t\t" + student[
                "WeChat"] + "\t")

        print("~" * 70)
        print("\n")

    # 删除学生信息


    def delete_info(self):
        Identify = input("请输入你要删除的学生编号")
        for student in self.students:
            if Identify == student.get("Identify"):
                self.students.remove(student)
                print("删除成功")


    def modify_info(self):
        name = input("请输入你要修改的学生姓名")
        for student in self.students:
            if name == student.get("name"):
                new_name = input("请输入新的姓名")
                student["name"] = new_name

        self.display()


    def find_info(self):
        name = input("请输入你要查找的学生姓名")
        flag = 0  # 默认都找了就是不存在
        for student in self.students:
            if name == student.get("name"):
                flag = 1
                print("\t学号\t姓名\t电话\t微信\t")
                print("~" * 70)
                print("\t" + student["Identify"] + "\t\t" + student["name"] + "\t\t" + student["phone"] + "\t\t" + student[
                    "WeChat"] + "\t")
                print("~" * 70)
            if flag == 0:
                print("没有找到[%s]" % name)
        # 保存信息，增加，删除，修改

    # 读取信息运行的时候
    def save_info(self):

        f=open("StudentForm.txt","w")
        f.write(str(self.students))
        f.close()

    def load_info(self):

        f = open("StudentForm.txt", "a+")
        f.seek(0)
        txt=f.read()
        if len(txt)>0:
            self.students=eval(txt)
        f.close()
    # 讲义个数1
    def main(self):
        self.print_menu()
        self.load_info()
        while True:
            print("\n")
            print("\t\t操作指令")
            print("~" * 50)
            infos = "1:增加|2:删除|3:修改|4:查找|5:显示|6:退出系统"
            print(infos)
            print("~" * 50)
            num = input("请输入相应的指令")
            print(num)
            if num == "1":
                print("增加")
                self.add_info()
                self.display()
                self.save_info()
            elif num == "2":
                print("删除")
                self.delete_info()
                self.display()
                self.save_info()
            elif num == "3":
                print("修改")
                self.modify_info()
            elif num == "4":
                print("查找")
                self.find_info()
            elif num == "5":
                print("显示")
                self.display()
            elif num == "6":
                print("退出系统")
                break
StudentSys().main()

